<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>公告添加</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="../../layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="../../css/public.css" media="all" />
</head>
<body class="childrenBody">
<form class="layui-form layui-row layui-col-space10">
	<input class="layui-hide" id="id" value="">
	<div class="layui-col-md9 layui-col-xs12">
		<div class="layui-row layui-col-space10">
			<div class="layui-form-item magt3">
				<label class="layui-form-label">公告标题</label>
				<div class="layui-input-block">
					<input type="text" class="layui-input title" lay-verify="title" placeholder="请输入公告标题">
				</div>
			</div>
			<div class="layui-form-item">
				<label class="layui-form-label">内容摘要</label>
				<div class="layui-input-block">
					<textarea placeholder="请输入内容摘要" class="layui-textarea abstract"></textarea>
				</div>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">公告内容</label>
			<div class="layui-input-block">
				<textarea class="layui-textarea content" placeholder="请输入公告内容" lay-verify="content"></textarea>
			</div>
		</div>
		<div class="layui-right">
				<a class="layui-btn layui-btn-bm" lay-filter="addNews" lay-submit><i class="layui-icon">&#xe609;</i> 发布</a>
				<a class="layui-btn layui-btn-primary layui-btn-bm" lay-filter="look" lay-submit>预览</a>
		</div>
	</div>
</form>
<script type="text/javascript" src="../../layui/layui.js"></script>
<script type="text/javascript">
layui.use(['form','layer'],function(){
    var form = layui.form
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery;
    
    function getRootPath(){  
        var curPath=window.document.location.href;  
        var pathName=window.document.location.pathname;  
        var pos=curPath.indexOf(pathName);  
        var localhostPaht=curPath.substring(0,pos);  
        var projectName=pathName.substring(0,pathName.substr(1).indexOf('/')+1);  
        return localhostPaht+projectName;
    }
        
    var path = getRootPath();
    form.verify({
        title : function(val){
            if(val == ''){
                return "公告标题不能为空";
            }
        },
        content : function(val){
            if(val == ''){
                return "公告内容不能为空";
            }
        }
    });
    
    form.on("submit(addNews)",function(data){
        //弹出loading
        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
        
        // 实际使用时的提交信息
        $.ajax({
  		  url: path + '/news/submit',
  		  data: {
              id: $("#id").val(),
         	  title : $(".title").val(),
              abstract : $(".abstract").val(),
              content : $(".content").val(),
          },
  		  dataType: 'json',
  		  type: 'post',
  		  success: function(ret){
  			  if(ret.state==="ok"){
         		 top.layer.msg("公告发布成功！");
                 layer.closeAll("iframe");
                 //刷新父页面
                 parent.location.reload();
  			  } else {
  				  top.layer.msg("公告发布失败！");
  			  }
  		  },
  	  	  error: function(){
  	  		top.layer.msg("公告发布失败！");
  			  }
  	  });
        return false;
    });
    
    
    //预览
    form.on("submit(look)",function(){
        layer.alert("唉，哪里有这么多时间开发这些玩意...如果有机会的话会完善的。");
        return false;
    });
});
</script>
</body>
</html>